<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    <%=FileLanguage.file_manager %>
</asp:Content>
<asp:content id="Content2" contentplaceholderid="MainContent" runat="server">
   
            <h2><%=FileLanguage.file_manager %></h2>
             <%= Html.ValidationSummary(FileLanguage.error)%>
            <%  string path = (string)ViewData["dir"]; %>
            <table width="100%">
            <tr>
            <th style="width: 40px">
            <img src="/content/files/Stuffed_Folder.png" style="height: 32px; " alt="root" />
            </th>
            <th>
            <%= Html.ActionLink(Membership.ApplicationName, "Index", new { id = string.Empty })%>
            <%
                if (path != "")
                {
                    string[] drs = path.Remove(0, 2).Replace("()", "/").Split('/');
                    string p = "";
                    foreach (string st in drs)
                    {
                        if (st == drs[drs.Length - 1])
                        {%>/<%=st%><%}
                        else
                        {
                            p += "()" + st;%>
            /<a href="<%=Url.Action("Index", "File", new{id=p})%>"><%=st%></a>
            <% }
                    }
                } %>
            </th>
            </tr>
            </table>
            <table width="100%">
                <tr>
                    <% using (Html.BeginForm("Create", "File", new { id = path }))
                       {%>
                    <th style="width: 10px;">
                    </th>
                    <th style="text-align: center;">
                        <%=FileLanguage.create_new_folder %>
                        <%= Html.TextBox("name")%>
                        <input type="submit" value="<%=FileLanguage.create %>" />
                    </th>
                    <% } %>
                    <% using (Html.BeginForm("Index", "File", FormMethod.Post,
                                new { enctype = "multipart/form-data" }))
                       {%>
                    <th style="text-align: center;">
                        <%=FileLanguage.upload_file %>
                        <input type="file" name="file" />
                        <input type="submit" value="<%=FileLanguage.upload %>" />
                    </th>
                    <% } %>
                </tr>
            </table>            
            <table width="100%">
                <tr>
                    <th style="width: 50px;">
                    </th>
                    <th style="width: 10px;">
                    </th>
                    <th style="text-align: center;">
                    </th>
                    <th style="text-align: center; width: 150px;">
                        <%=FileLanguage.change_date  %>
                    </th>
                    <th style="width: 110px; text-align: center">
                        <%=FileLanguage.size %>
                    </th>
                </tr>
                <% foreach (System.IO.DirectoryInfo x in (IEnumerable)ViewData["folder"])
                   {
                       string url = path + "()" + x.Name;
                %>
                <tr>
                    <td align="center">
                        <div>
                            <a href="<%=Url.Action("Rename", "File", new {  id=url, t = "folder" })%>">
                                <img src="/content/images/rename.png" alt="FileLanguage.rename" style="border-width: 0px; width: 20px;" /></a>
                            <a href="<%=Url.Action("Delete", "File", new{id=url, t = "folder"})%>" onclick="return confirm ('<%= FileLanguage.are_you_sure%>');">
                                <img src="/content/images/delete.png" alt="FileLanguage.delete" style="border-width: 0px; width: 20px;" /></a>
                        </div>
                    </td>
                    <td  align="center">
                        <a href="<%=Url.Action("Index", "File", new{id=url})%>">
                        <img src="/content/files/Stuffed_Folder.png" style="height: 32px; border-width: 0px;"
                                    alt="<%=x.Name %>" /></a>
                    </td>
                    <td>
                        <a href="<%=Url.Action("Index", "File", new{id=url})%>">
                            <%=x.Name %></a>
                    </td>
                    <td>
                    </td>
                    <td>
                    </td>
                </tr>
                <%}
                   foreach (System.IO.FileInfo x in (IEnumerable)ViewData["file"])
                   {
                       string url = (path + "/" + x.Name).Replace("()", "/");
                       if (x.Extension != ".ico" && x.Extension != ".png" && x.Extension != ".jpg" && x.Extension != ".gif")
                       { url = "/content/files/" + x.Extension + ".png"; }
                       string fpath = path + "()" + x.Name;%>
                <tr>
                    <td align="center">
                        <div>
                            <a href="<%=Url.Action("Rename", "File", new {  id=fpath, t = "file" })%>">
                                <img src="/content/images/rename.png" alt="<%= FileLanguage.rename%>" style="border-width: 0px; width: 20px;" /></a>
                            <a href="<%=Url.Action("Delete", "File", new{id=fpath, t = "file"})%>" onclick="return confirm ('<%= FileLanguage.are_you_sure%>');">
                                <img src="/content/images/delete.png" alt="<%= FileLanguage.delete%>" style="border-width: 0px; width: 20px;" /></a>
                        </div>
                    </td>
                    <td align="center">
                        <img src="<%= url %>" style="height: 32px;" alt="<%=x.Name %>" />
                    </td>
                    <td>
                        <a href="<%= fpath.Replace("()", "/") %>">
                            <%= x.Name%></a>
                    </td>
                    <td class="file_file">
                        <%=x.LastWriteTime %>
                    </td>
                    <td class="file_file">
                        <%=x.Length %>
                        <%=FileLanguage.bytes%>
                    </td>
                </tr>
                <%}%>
            </table>
</asp:content>
